Skip to content

fix(debugger): handle Invalid Date in snapshot processor#7944

Open
watson wants to merge 1 commit intomasterfrom
watson/fix-debugger-snapshot-date-collection
Open

fix(debugger): handle Invalid Date in snapshot processor#7944
watson wants to merge 1 commit intomasterfrom
watson/fix-debugger-snapshot-date-collection

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Apr 7, 2026

What does this PR do?

Fixes a RangeError crash in the Dynamic Instrumentation snapshot processor when capturing an Invalid Date object at a breakpoint.

Date.prototype.toISOString() throws a RangeError when called on an Invalid Date (e.g. new Date('invalid')). Since the Chrome DevTools Protocol still reports these as subtype: 'date', the snapshot processor would hit this code path and crash. The fix checks date.getTime() for NaN before calling toISOString(), falling back to the raw description string ("Invalid Date") when the date is not valid.

Motivation

If a variable holding an Invalid Date exists at a breakpoint location, the RangeError is thrown inside the Debugger.paused event handler. Since this runs in the devtools client worker thread, it would not crash the instrumented application itself, but it would cause the snapshot collection to fail silently — the breakpoint would appear to hang and no snapshot data would be sent to Datadog.

Additional Notes

A test for this case has been added to the existing complex-types snapshot test suite.

Calling `toISOString()` on an Invalid Date throws a RangeError. This
could happen when a user has a variable holding `new Date('invalid')`
at a breakpoint. Fall back to the raw description string when the
date is not valid.
@watson watson requested a review from a team as a code owner April 7, 2026 19:41
@watson watson self-assigned this Apr 7, 2026
Copy link
Copy Markdown
Collaborator Author

watson commented Apr 7, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@watson watson added semver-patch debugger Dynamic Instrumentation & Live Debugger labels Apr 7, 2026
@watson watson requested a review from a team April 7, 2026 19:41
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Overall package size

Self size: 5.47 MB
Deduped: 6.32 MB
No deduping: 6.32 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.06%. Comparing base (efc9681) to head (74d70b2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7944      +/-   ##
==========================================
- Coverage   74.25%   71.06%   -3.20%     
==========================================
  Files         769      768       -1     
  Lines       36068    36058      -10     
==========================================
- Hits        26783    25623    -1160     
- Misses       9285    10435    +1150     
Flag Coverage Δ
aiguard-macos ?
aiguard-ubuntu 39.56% <ø> (-0.10%) ⬇️
aiguard-windows 39.23% <ø> (-0.10%) ⬇️
apm-capabilities-tracing-macos 49.56% <ø> (ø)
apm-capabilities-tracing-ubuntu ?
apm-capabilities-tracing-windows 49.34% <ø> (+0.04%) ⬆️
apm-integrations-child-process 38.74% <ø> (-0.10%) ⬇️
apm-integrations-couchbase-18 ?
apm-integrations-couchbase-eol 37.87% <ø> (-0.27%) ⬇️
apm-integrations-oracledb 37.87% <ø> (-0.10%) ⬇️
appsec-express 55.38% <ø> (-0.08%) ⬇️
appsec-fastify 51.71% <ø> (-0.07%) ⬇️
appsec-graphql 51.87% <ø> (-0.07%) ⬇️
appsec-kafka 44.49% <ø> (-0.08%) ⬇️
appsec-ldapjs 44.11% <ø> (-0.08%) ⬇️
appsec-lodash 43.71% <ø> (-0.08%) ⬇️
appsec-macos 58.09% <ø> (-0.07%) ⬇️
appsec-mongodb-core ?
appsec-mongoose 49.55% <ø> (-0.08%) ⬇️
appsec-mysql 51.08% <ø> (-0.07%) ⬇️
appsec-node-serialize 43.29% <ø> (-0.08%) ⬇️
appsec-passport 47.76% <ø> (-0.09%) ⬇️
appsec-postgres 50.70% <ø> (-0.07%) ⬇️
appsec-sourcing 42.54% <ø> (-0.08%) ⬇️
appsec-stripe 44.73% <ø> (-0.09%) ⬇️
appsec-template 43.45% <ø> (-0.08%) ⬇️
appsec-ubuntu ?
appsec-windows 57.91% <ø> (-0.05%) ⬇️
instrumentations-instrumentation-bluebird 32.33% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-body-parser 40.63% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-child_process 38.07% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-cookie-parser 34.36% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express 34.67% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-express-mongo-sanitize ?
instrumentations-instrumentation-express-session 40.27% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-fs ?
instrumentations-instrumentation-generic-pool 29.41% <ø> (ø)
instrumentations-instrumentation-http 39.99% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-knex 32.39% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-mongoose 33.51% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-multer 40.38% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-mysql2 38.40% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-passport 44.16% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-http 43.84% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-passport-local 44.37% <ø> (-0.09%) ⬇️
instrumentations-instrumentation-pg 37.84% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-promise 32.26% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-promise-js 32.26% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-q 32.31% <ø> (-0.10%) ⬇️
instrumentations-instrumentation-url 32.23% <ø> (-0.11%) ⬇️
instrumentations-instrumentation-when 32.28% <ø> (-0.11%) ⬇️
llmobs-ai 41.37% <ø> (-0.10%) ⬇️
llmobs-anthropic ?
llmobs-bedrock 39.32% <ø> (-0.08%) ⬇️
llmobs-google-genai 39.87% <ø> (-0.09%) ⬇️
llmobs-langchain 39.34% <ø> (-0.08%) ⬇️
llmobs-openai ?
llmobs-vertex-ai 40.13% <ø> (-0.09%) ⬇️
platform-core ?
platform-esbuild ?
platform-instrumentations-misc 34.11% <ø> (ø)
platform-shimmer ?
platform-unit-guardrails 32.89% <ø> (ø)
platform-webpack 19.86% <ø> (ø)
plugins-azure-durable-functions 25.74% <ø> (ø)
plugins-azure-event-hubs 25.90% <ø> (ø)
plugins-azure-service-bus 25.26% <ø> (ø)
plugins-bullmq ?
plugins-cassandra 38.02% <ø> (-0.10%) ⬇️
plugins-cookie 26.96% <ø> (ø)
plugins-cookie-parser 26.75% <ø> (ø)
plugins-crypto 26.73% <ø> (ø)
plugins-dd-trace-api 38.43% <ø> (-0.10%) ⬇️
plugins-express-mongo-sanitize 26.89% <ø> (ø)
plugins-express-session 26.70% <ø> (ø)
plugins-fastify 42.36% <ø> (-0.09%) ⬇️
plugins-fetch 38.51% <ø> (-0.12%) ⬇️
plugins-fs 38.75% <ø> (-0.10%) ⬇️
plugins-generic-pool 25.94% <ø> (ø)
plugins-google-cloud-pubsub 45.68% <ø> (-0.09%) ⬇️
plugins-grpc ?
plugins-handlebars 26.94% <ø> (ø)
plugins-hapi 40.27% <ø> (-0.10%) ⬇️
plugins-hono 40.61% <ø> (-0.24%) ⬇️
plugins-ioredis 38.60% <ø> (-0.10%) ⬇️
plugins-knex 26.57% <ø> (ø)
plugins-langgraph 37.99% <ø> (-0.10%) ⬇️
plugins-ldapjs 24.43% <ø> (ø)
plugins-light-my-request 26.30% <ø> (ø)
plugins-limitd-client 32.61% <ø> (-0.10%) ⬇️
plugins-lodash 26.03% <ø> (ø)
plugins-mariadb 39.61% <ø> (-0.10%) ⬇️
plugins-memcached 38.34% <ø> (-0.10%) ⬇️
plugins-microgateway-core 39.34% <ø> (-0.10%) ⬇️
plugins-moleculer 40.63% <ø> (-0.09%) ⬇️
plugins-mongodb 39.27% <ø> (-0.10%) ⬇️
plugins-mongodb-core 39.14% <ø> (-0.07%) ⬇️
plugins-mongoose 38.92% <ø> (-0.10%) ⬇️
plugins-multer 26.70% <ø> (ø)
plugins-mysql 39.45% <ø> (-0.10%) ⬇️
plugins-mysql2 39.41% <ø> (-0.10%) ⬇️
plugins-node-serialize 27.00% <ø> (ø)
plugins-opensearch 37.74% <ø> (-0.10%) ⬇️
plugins-passport-http 26.76% <ø> (ø)
plugins-postgres 35.54% <ø> (-0.09%) ⬇️
plugins-process 26.73% <ø> (ø)
plugins-pug 26.96% <ø> (ø)
plugins-redis 39.04% <ø> (-0.10%) ⬇️
plugins-router 43.36% <ø> (-0.10%) ⬇️
plugins-sequelize 25.55% <ø> (ø)
plugins-test-and-upstream-amqp10 ?
plugins-test-and-upstream-amqplib 44.37% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-apollo 39.24% <ø> (-0.09%) ⬇️
plugins-test-and-upstream-avsc 38.69% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-bunyan 33.94% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-connect 40.93% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-graphql 40.28% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-koa 40.52% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-protobufjs 38.92% <ø> (-0.10%) ⬇️
plugins-test-and-upstream-rhea 44.37% <ø> (-0.10%) ⬇️
plugins-undici 39.36% <ø> (-0.09%) ⬇️
plugins-url 26.73% <ø> (ø)
plugins-valkey 38.31% <ø> (-0.10%) ⬇️
plugins-vm 26.73% <ø> (ø)
plugins-winston 34.12% <ø> (-0.24%) ⬇️
plugins-ws 42.12% <ø> (-0.10%) ⬇️
profiling-macos 40.65% <ø> (-0.10%) ⬇️
profiling-ubuntu 40.78% <ø> (-0.10%) ⬇️
profiling-windows 42.30% <ø> (-0.10%) ⬇️
serverless-azure-functions-client 25.62% <ø> (ø)
serverless-azure-functions-eventhubs ?
serverless-azure-functions-servicebus ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 bot commented Apr 7, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 68.69% (-0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 74d70b2 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Apr 7, 2026

Benchmarks

Benchmark execution time: 2026-04-07 19:52:48

Comparing candidate commit 74d70b2 in PR branch watson/fix-debugger-snapshot-date-collection with baseline commit efc9681 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 229 metrics, 31 unstable metrics.

// in the `description` field. Unfortunately that's all we get from the Chrome DevTools Protocol.
return { type: obj.className, value: `${new Date(obj.description).toISOString().slice(0, -5)}Z` }
const date = new Date(obj.description)
const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`
const value = Number.isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

debugger Dynamic Instrumentation & Live Debugger semver-patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants